<template>
	<view>
		<view class="header">
			<image src="../../../static/icons/arrl.png" mode=""@tap="back"></image>
			<text>乐居</text>
		</view>
		<view class="editUser">
			<view @tap="isShow=!isShow">修改用户信息</view>
		</view>
		<view class="list">
			<view class="item">
				<view>头像</view>
				<view class="pic" v-if="isShow">
					<image :src="icon" mode=""></image>
				</view>
				<view class="title" v-else>上传头像</view>
			</view>
			<view class="item">
				<view>用户名</view>
				<view>
				<input :class="isShow ? 'act' : ''" type="text" v-model="username" :disabled="isShow" />
				</view>
			</view>
			<view class="item">
				<view>昵称</view>
				<view>
				<input :class="isShow ? 'act' : ''" type="text" v-model="nickname":disabled="isShow" /></view>
			</view>
			<view class="item">
				<view>手机号</view>
				<view>
				<input :class="isShow ? 'act' : ''" type="text" v-model="phone" :disabled="isShow" />
				</view>
			</view>
		</view>
		<view class="btn">
			<view v-if="isShow" @tap="jumpLogin">退出登陆</view>
			<view v-else @tap="newInfo">更 新</view>
		</view>
	</view>
</template>

<script>
	import { getMemberInfo,updateMemberInfo } from "../../../api/user/index.js"
	export default {
		data() {
			return {
				data:{},
				isShow:true,
				icon:"",
				phone:"",
				id:"",
				username:"",
				nickname:"",
				password:""
			};
		},
		methods: {
			back() {
				uni.switchTab({
					url:"/pages/user/user"
				})
			},
			jumpLogin() {
				uni.navigateTo({
					url:"/pages/user/login/login"
				})
			},
			newInfo() {
				updateMemberInfo({
					birthday: null,
					city: "",
					createTime: "2020-09-22 10:19:14",
					email: null,
					growth: null,
					historyIntegration: null,
					icon: this.icon,
					id: this.id,
					integration: null,
					isDisabled: 0,
					memberLevelId: null,
					modifyTime: "2021-01-05 11:55:27",
					nickname: this.nickname,
					password: this.password,
					personalizedSignature: "",
					phone: this.phone,
					realname: null,
					sex: null,
					sourceType: null,
					status: null,
					username: this.username,
					wxOpenId: null
				}).then(res=>{
					console.log(res)
					if(res.success) {
						uni.showToast({
							title:"更新成功,需要重新登录",
							success() {
								setTimeout(()=>{
									uni.navigateTo({
										url:"/pages/user/login/login"
									})
								},1500)
							}
						})
					}
				})
			}
		},
		onLoad() {
			getMemberInfo().then(res=>{
				console.log(res)
				this.data = res.data.userInfo
				console.log(this.data)
				this.id = this.data.id
				this.icon = this.data.icon
				this.phone = this.data.phone
				this.username = this.data.username
				this.nickname = this.data.nickname
				this.password = this.data.password
			})
		}
	}
</script>

<style lang="scss" scoped>
.header {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #354e44;
	height: 60rpx;
	padding: 14rpx 6rpx;
	image {
		position: absolute;
		left: 4rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
	}
	text {
		font-size: 32rpx;
		color: #FFFFFF;
		font-weight: bolder;
	}
}
.editUser {
	display: flex;
	justify-content: flex-end;
	>view {
		font-size: 26rpx;
		line-height: 2.3;
		color: #353535;
		padding: 0 1.34rem;
		border: 1px solid #353535;
		border-radius: 12rpx;
		margin: 20rpx;
	}
}
.list {
	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10rpx 30rpx;
		font-size: 32rpx;
		border-bottom: 1px solid #e5e5e5;
		box-sizing: border-box;
		line-height: 94rpx;
		
		>view {
			&:last-child {
				input {
					display: block;
					text-align: right;
					&.act {
						color: #a1a1a1;
					}
				}
			}
		}
		&:first-child {
			>.title {
				color: #353535;
				    line-height: 2.3;
				    font-size: 13px;
				    padding: 0 1.34em;
					border: 1px solid #353535;
					border-radius: 12rpx;
			}
			
			.pic {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					overflow: hidden;
					image {
						width: 100%;
						height: 100%;
					}
			}
		}
	}
}
.btn {
	position: fixed;
	left: 50%;
	bottom: 20%;
	margin-left: -184rpx;
		width: 314rpx;
		height: 88rpx;
		padding: 0 28rpx;
		border-radius: 12rpx;
		background-color: #1c4b47;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
}
</style>
